#define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0;i < n; i++)
    {
        int tmp = 0;
        cin >> tmp;
        m[tmp]++;
    }

    int ret = INT_MIN;
    for (int i = 0; i < m.size();i++)
    {
        map<int, int> tmp(m.begin(), m.end());
        int count = 0;
        for (auto e : tmp)
        {
            tmp.erase(e.first - 1);
            tmp.erase(e.first + 1);
            count += e.first * e.second;
        }
        ret = max(ret, count);
    }

    cout << ret << endl;

    return 0;
}